
$(function(){
    var dataX = [];//
    var dataStockGroup = [];//
    var dataStockDonation = [];//
    var dataStockOwn = [];//
    var dataDemandOfThree = [];//
    var dataDemandOfSeven = [];//
    
    $.ajax({
        type: "post",
        url: "material/fetchStatisticDate",
        dataType: "json",
        success: function (data) {
        	$("#statisticDate").html(data[0].statisticDate);
    	}
    });
    for(var i=1;i<=11;i++){
    	(function(i){
            $.ajax({
            	type: "post",
                url: "material/fetchMaterial",
                dataType: "json",
                data: {categoryId: i},
                success: function (data) {
                	dataX = [];//口罩
                    dataStockGroup = [];//口罩
                    dataStockDonation = [];//口罩
                    dataStockOwn = [];//口罩
                    dataDemandOfThree = [];//口罩
                    dataDemandOfSeven = [];//口罩
                	for(var j in data){
                		dataX.push(data[j].statisticDate);
                		dataStockGroup.push(data[j].stockGroup);
                		dataStockDonation.push(data[j].stockDonation);
                		dataStockOwn.push(data[j].stockOwn);
                		dataDemandOfThree.push(data[j].demandOfThree);
                		dataDemandOfSeven.push(data[j].demandOfSeven);
                	}
                	drawEcharts(dataX,dataStockGroup,dataStockDonation,dataStockOwn,dataDemandOfThree,dataDemandOfSeven,i);
            	}
            })
    	})(i)
      
    }
    
    
});

function drawEcharts(dataX,dataStockGroup,dataStockDonation,dataStockOwn,dataDemandOfThree,dataDemandOfSeven,i){
	
	var myChart;
	if(i==1){
		myChart = echarts.init(document.getElementById('mask'));//口罩
	}
	if(i==2){
		myChart = echarts.init(document.getElementById('glove'));//手套
	}
	if(i==3){
		myChart = echarts.init(document.getElementById('protectiveClothing'));//防护服
	}
	if(i==4){
		myChart = echarts.init(document.getElementById('alcoholCotton'));//酒精棉
	}
	if(i==5){
		myChart = echarts.init(document.getElementById('goggles'));//护目镜
	}
	if(i==6){
		myChart = echarts.init(document.getElementById('disinfectant'));//消毒液
	}
	if(i==7){
		myChart = echarts.init(document.getElementById('alcohol'));//酒精
	}
	if(i==8){
		myChart = echarts.init(document.getElementById('liquidSoap'));//洗手液
	}
	if(i==9){
		myChart = echarts.init(document.getElementById('foreheadThermometer'));//额温枪
	}
	if(i==10){
		myChart = echarts.init(document.getElementById('thermalImager'));//热像仪
	}
	if(i==11){
		myChart = echarts.init(document.getElementById('ultravioletLamp'));//紫外线灯
	}
	
	
	
	option = {
		    tooltip: {
		        trigger: "axis",
		        axisPointer: {
		            type: "shadow",
		            textStyle: {
		                color: "#fff"
		            }

		        }
		    },
		    
		    grid: {
		        borderWidth: 0,
		        top: 60,//防止和legend重叠
		        left: '16%',//防止和legend重叠
		        bottom: 80,//防止和datazoom重叠
		        textStyle: {
		            color: "#fff"
		        }
		    },
		    legend: [
		    	{
		            x:'center',
		            data: ['集团采购库存', '捐赠库存', '运营公司自有库存']
		        },
		        {
		            x:'center',
		            top:'8%',
		            data: ['3日需求','7日需求']
		        }
		    ],
		     

//		    calculable: true,
		    xAxis: [{
		        type: "category",
		        axisLine: {
		            lineStyle: {
		                color: '#90979c'
		            }
		        },
		        splitLine: {
		            "show": false
		        },
		        axisTick: {
		            "show": false
		        },
		        splitArea: {
		            "show": false
		        },
		        axisLabel:{
		        	rotate : 45
		        },
		        data: dataX
		    }],
		    yAxis: [{
		        type: "value",
		        splitLine: {
		            "show": false
		        },
		        axisLine: {
		            lineStyle: {
		                color: '#90979c'
		            }
		        },
		        axisTick: {
		            "show": false
		        },
		        axisLabel: {
		            "interval": 0,

		        },
		        splitArea: {
		            "show": false
		        },

		    }],
		    dataZoom: [{
		        show: true,
		        height: 20,
		        startValue: dataX.length-10,
		        handleStyle:{
		            color:"#d3dee5",
		            
		        },
	           textStyle:{
	        	   color:"#fff"
        	   },
	           borderColor:"#90979c"
		        
		    }, {
		        type: "inside",
		        show: true,
		        height: 15,
		        start: 1,
		        end: 35
		    }],
		    series: [{
		            name: "集团采购库存",
		            type: "bar",
		            stack: "total",
		            barWidth: 15,
		            itemStyle: {
		                normal: {
		                    color: "#BF0000",
		                }
		            },
		            data: dataStockGroup,
		        },
		        {
		            name: "捐赠库存",
		            type: "bar",
		            stack: "total",
		            barWidth: 20,
		            itemStyle: {
		                normal: {
		                    color: "#EC7C30",
		                    barBorderRadius: 0,
		                }
		            },
		            data: dataStockDonation
		        },
		        {
		            name: "运营公司自有库存",
		            type: "bar",
		            stack: "total",
		            barWidth: 20,
		            itemStyle: {
		                normal: {
		                    color: "#4371C3",
		                    barBorderRadius: 0,
		                }
		            },
		            data: dataStockOwn
		        }, 
		        
		        {
		            name: "3日需求",
		            type: "line",
		            symbolSize:10,
		            symbol:'circle',
		            smooth: true,
		            itemStyle: {
		                normal: {
		                    color: "grey",
		                    barBorderRadius: 0,
		                    label: {
		                        show: false,
		                        position: "top",
		                    }
		                }
		            },
		            data: dataDemandOfThree
		        },
		        {
		            name: "7日需求",
		            type: "line",
		            symbolSize:10,
		            symbol:'circle',
		            smooth: true,
		            itemStyle: {
		                normal: {
		                    color: "black",
		                    barBorderRadius: 0,
		                    label: {
		                        show: false,
		                        position: "top",
		                    }
		                }
		            },
		            data: dataDemandOfSeven
		        }
		    ]
		}
	myChart.setOption(option);
}
